package com.etc.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.etc.entity.Person;
import com.etc.service.ManagerService;
import com.etc.service.impl.ManagerServiceImpl;

public class FindByAccount extends HttpServlet {

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//获取参数
		String account="";
		if(request.getParameter("content")!=null)
		account = request.getParameter("content");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		// 2. 把请求参数封装到entity中
			List<Person> list = null;
		// 3. 调用业务对象
		ManagerService m= new ManagerServiceImpl();
		list=m.findByAccount(account);
		if(list!=null){
		String jsonStr = JSON.toJSONString(list);// 利用阿里的工具包，把JAVA对象转换成JSON的文本格式
		out.print(jsonStr);
		out.flush();
		out.close();
		}else{
	    String jsonStr = JSON.toJSONString("none");
	    out.print(jsonStr);
		out.flush();
		out.close();
		}
}
}
